import request from '/@/utils/request';
const serverContextPath = '/xxljob'
export function scheduleApi() {
	return {
		/**
		 * 查询定时任务执行器列表
		 * @returns list
		 */
		getXxlJobGroupList: () => {
			return request({
				url: serverContextPath + `/jobgroup/getList`,
				method: 'get'
			})
		},

		/**
		 * 删除执行器
		 * @param {*} id
		 * @returns
		 */
		deleteXxlJobGroup: (id: any) => {
			return request({
				url: serverContextPath + `/jobgroup/delete/${id}`,
				method: 'get'
			})
		},

		/**
		 * 保存执行器
		 * @param {*} data
		 * @returns
		 */
		saveXxlJobGroup: (data: any) => {
			return request({
				url: serverContextPath + '/jobgroup/saveJobGroup',
				method: 'post',
				data: data
			})
		},

		/**
		 * 分页查询任务列表
		 * @param {*} params
		 * @returns
		 */
		getXxlJobJobList: (params: any) => {
			return request({
				url: serverContextPath + '/jobinfo/getList',
				method: 'get',
				params: params
			})
		},

		/**
		 * 保存定时任务
		 * @param {*} data
		 * @returns
		 */
		saveXxlJobInfo: (data: any) => {
			return request({
				url: serverContextPath + '/jobinfo/saveJobInfo',
				method: 'post',
				data: data
			})
		},

		/**
		 * 删除定时任务
		 * @param {*} id
		 * @returns
		 */
		deleteXxlJobInfo: (id: any) => {
			return request({
				url: serverContextPath + `/jobinfo/delete/${id}`,
				method: 'get'
			})
		},

		/**
		 * 执行一次
		 * @param {*} id 任务id
		 * @param {*} value 参数
		 * @returns
		 */
		runJobInfo: (id: any, value: any) => {
			return request({
				url: serverContextPath + `/jobinfo/runJobInfo`,
				method: 'post',
				data: {
					'id': id,
					'executorParam': value
				}
			})
		},

		/**
		 * 查看注册节点
		 * @param {*} id
		 * @returns
		 */
		getRegistryinJobInfo: (id: any) => {
			return request({
				url: serverContextPath + `/jobgroup/getRegistryinJobInfo/${id}`,
				method: 'get'
			})
		},

		/**
		 * 查看下次执行时间
		 * @param {*} cron
		 * @returns
		 */
		getNextTimeJobInfo: (scheduleType: any, cron: any) => {
			return request({
				url: serverContextPath + `/jobinfo/getNextTimeJobInfo`,
				method: 'post',
				data: {
					'scheduleType': scheduleType,
					'scheduleConf': cron
				}
			})
		},

		/**
		 * 启动任务
		 * @param {*} id
		 * @returns
		 */
		startJobInfo: (id: any) => {
			return request({
				url: serverContextPath + `/jobinfo/startJobInfo/${id}`,
				method: 'get'
			})
		},

		/**
		 * 启动任务
		 * @param {*} id
		 * @returns
		 */
		stopJobInfo: (id: any) => {
			return request({
				url: serverContextPath + `/jobinfo/stopJobInfo/${id}`,
				method: 'get'
			})
		},

		/**
		 * 分页查询任务日志列表
		 * @param {*} params
		 * @returns
		 */
		getXxlJobLogList: (params: any) => {
			return request({
				url: serverContextPath + '/joblog/getList',
				method: 'get',
				params: params
			})
		},

		/**
		 * 终止正在执行的任务
		 * @param {*} id
		 * @returns
		 */
		killJobIns: (id: any) => {
			return request({
				url: serverContextPath + `/joblog/killJobIns/${id}`,
				method: 'get'
			})
		},

		/**
		 * 查询日志
		 * @param {*} id
		 * @returns
		 */
		logDetailCatInfo: (executorAddress: any, triggerTime: any, id: any, fromLineNum: any) => {
			return request({
				url: serverContextPath + `/joblog/logDetailCatInfo`,
				method: 'get',
				params: {
					'executorAddress': executorAddress,
					'triggerTime': triggerTime,
					'logId': id,
					'fromLineNum': fromLineNum
				}
			})
		}
	}
}
